package diploma.kisel.modelas.service;

import java.util.ArrayList;
import java.util.List;

import diploma.kisel.modelas.domain.Concept;
import diploma.kisel.modelas.domain.Workstation;
import diploma.kisel.modelas.repository.WorkstationRepositoryImpl;
import diploma.kisel.modelas.repository.api.WorkstationRepository;
import diploma.kisel.modelas.service.api.WorkstationService;

public class WorkstationServiceImpl implements WorkstationService {

	private WorkstationRepository workstationRepository = new WorkstationRepositoryImpl();

	@Override
	public List<Workstation> findAll() {
		return workstationRepository.findAll();
	}

	@Override
	public Workstation findById(int id) {
		if (id >= 0)
			return workstationRepository.findById(id);
		else
			return null;
	}

	@Override
	public Workstation save(Workstation workstation) {
		if (workstation != null)
			if (workstation.getId() != null)
				return workstationRepository.update(workstation);
			else
				return workstationRepository.save(workstation);
		return null;
	}

	@Override
	public void remove(Workstation workstation) {
		if (workstation != null && workstation.getId() != null)
			workstationRepository.remove(workstation);
	}

	@Override
	public void remove(int id) {
		Workstation workstation = findById(id);
		remove(workstation);
	}

	@Override
	public List<Workstation> findByConcept(Concept concept) {
		if (concept!=null)
			return workstationRepository.findByConcept(concept);
		return new ArrayList<>();
	}

}
